<style type="text/css">
#teste
{
    padding: 0;
    margin: 0;
}
#cas
{
    padding-left: 1%;
    padding-bottom: 0;
    border: 0;
}
.tabbar {
  margin-top: 10px;
  border-bottom: 3px solid #000;
  padding: 2px 0px;
  font-family: sans-serif;
  font-size: 83%;
}
.tabbar ul, li {
  margin: 0;
  padding: 0;
  display: inline;
  list-style: none;
}
.tabbar a {
  padding: 2px 1em;
  border-top: 1px solid #ccc;
  border-left: 1px solid #ccc;
  border-right: 1px solid #ccc;
  border-bottom: none;
  background-color: #ffffff;
  color: #000;
  text-decoration: none;
}
.tabbar a:hover, .tabbar a:active {
  border-top: 1px solid blue;
  border-left: 1px solid blue;
  border-right: 1px solid blue;
  background-color: #fff;
  color: blue;
  text-decoration: underline;
}
.tabbar a.tabact {
  border-bottom: 1px solid #000;
  background-color: #000;
  color: white;
  font-weight: bold;
}
.tabbar a.tabact:hover,
.tabbar a.tabact:active {
  background-color: #000;
  color: white;
}
</style>
<?php
    $xml = "./bibliotecas/maple_valid.xml";

    if (isset($_GET['topico']) && isset($_GET['item']))
    {
        $dom = new DomDocument();
        $dom->load($xml);
        $subjects = $dom->getelementsbytagname("subject");
        if ($subjects->length > $_GET['topico'])
        {
            $items = $subjects->item($_GET['topico'])->getelementsbytagname("item");
            $assunto = $subjects->item($_GET['topico'])->getattribute("name");
            if ($items->length > $_GET['item'])
            {
                $item = $items->item($_GET['item']);
                $nome = $item->getattribute("name");
                $desc = $item->getelementsbytagname("description")->item(0)->nodeValue;
                $relcoms = $item->getElementsByTagname("command");
?>
        <h1><?php echo $assunto ?></h2>
        <h2><?php echo $nome ?></h2>
<?php
?>
<div id="teste">
<?php
    if (!empty($desc))
    {
?>
        <p><strong><?php echo $msg->get('Descricao') ?>:</strong> <?php echo $desc ?></p>
<?php
        $i = 0;
        foreach ($relcoms as $c)
        {
            if (!empty($c))
            {
                if ($i == 0)
                {
                    echo "<p><strong>".$msg->get('Comandos_Relacionados').":</strong> ";
                }
                else
                {
                    echo ", ";
                }
                $i++;
                echo $c->nodeValue;
            }
        }
        if ($i > 0) echo "</p>";
    }
?>
<div class="tabbar">
    <ul>
    <li><a href="index.php?inc=cas_load_system_maple2.php&execucao=1&topico=<?php echo $_GET['topico'] ?>&item=<?php echo $_GET['item'] ?>"<?php if ($_GET['execucao'] == 1) echo " class=\"tabact\""; ?>><?php echo $msg->get('Ajuda') ?></a></li>
    <li><a href="index.php?inc=cas_load_system_maple2.php&execucao=2&topico=<?php echo $_GET['topico'] ?>&item=<?php echo $_GET['item'] ?>"<?php if ($_GET['execucao'] == 2) echo " class=\"tabact\""; ?>><?php echo $msg->get('Exemplo') ?></a></li>
    <li><a href="index.php?inc=cas_load_system_maple2.php&execucao=3&topico=<?php echo $_GET['topico'] ?>&item=<?php echo $_GET['item'] ?>"<?php if ($_GET['execucao'] == 3) echo " class=\"tabact\""; ?>><?php echo $msg->get('Exercicio') ?></a></li>
    </ul>
</div>
<div id="cas">
<?php
                if ($_GET['execucao'] == 1)
                {
                    $filehelp = $item->getelementsbytagname("filehelp")->item(0)->nodeValue;
?>
                        <p><?php echo $msg->get('Msg_Ajuda') ?></p>
                        <p><a href="#" onClick="window.open('maplehelp.php?comando=<?php echo $filehelp ?>', 'Ajuda', 'toolbar=no, location=no, directories=no, scrollbars=yes,resizable=yes,menubar=no,width=600,height=350')"><strong><?php echo $msg->get('Ajuda') ?></strong></a></p>
<?php
                }
                elseif ($_GET['execucao'] == 2)
                {
                    $i = 0;
                    $example = $item->getelementsbytagname("example");
                    $example = $example->item(0);
                    $params = $example->getelementsbytagname("sentence");
                    $remark = $example->getelementsbytagname("remark");
                    $remark = $remark->item($remark->length - 1)->nodeValue; 
                    foreach ($params as $p)
                        $param[$i++] = $p->nodeValue;

                    include("config.php");
                    $descriptorspec = array(
                        0 => array("pipe", "r"),
                        1 => array("pipe", "w"),
                        2 => array("file", $DOCUMENT_ROOT."/error-scilab-output.txt", "a")
                    );
                    $env = array('HOME' => $DOCUMENT_ROOT,'DISPLAY' => '0', 'LD_ASSUME_KERNEL' => '2.4.1');
                    $process = proc_open('/usr/local/maple/bin/maple', $descriptorspec, $pipes, $cwd, $env);
                    if (is_resource($process)) {
                        $str1 = array("%","'");
                        $str2 = array("\%","''");
                        for ($i=0; $i<count($param);$i++)
                            fwrite($pipes[0],$param[$i]."\n");
                        fclose($pipes[0]);
                        echo "<pre>\n";	
                        echo stream_get_contents($pipes[1]);
                        echo "\n</pre>\n";
                        fclose($pipes[1]);
                        $return_value = proc_close($process);
                    }
                    if (!empty($remark))
                    {
?>
                <strong><?php echo $msg->get('Comentario') ?>:</strong> <?php echo $remark ?>
<?php
                    }
                }
                elseif ($_GET['execucao'] == 3)
                {
                    $exer = $item->getelementsbytagname("exercises")->item(0);
                    $descrip = $exer->getelementsbytagname("description")->item(0)->nodeValue;
                    $hint = $exer->getelementsbytagname("hint")->item(0)->nodeValue;
?>
            <p><strong><?php echo $msg->get('Descricao') ?></strong>: <?php echo $descrip ?></p>
            <p><strong><?php echo $msg->get('Dica') ?></strong>: <?php echo $hint ?></p>
<?php
                }
            }
        }
    }
?>
</div>
</div>
